/*
 * 常用的公用类
 */
var common = {};
common.string = {};
common.om = {"C":"common","S":"string"};
//ajax 请求包装类  sendAsyncRequest 需要设定同步异步模式  sendRequest 为异步模式
common.Request = function() {
	this.request = null;
	this.sendAsyncRequest = function(method, url, data, async, successHandler,
			errorHandler) {
		this.request = $.ajax( {
			type : method,
			url : url,
			dataType : "json",
			data : data,
			async : async,
			contentType : "application/x-www-form-urlencoded; charset=utf-8",
			success : successHandler,
			error : errorHandler
		});
	}
	this.sendMethodRequest = function(method, url, data, successHandler, errorHandler) {
		this.sendAsyncRequest(method, url, data, true, successHandler, errorHandler);
	}
	this.sendRequest = function(url, data, successHandler, errorHandler) {
		this.sendAsyncRequest("post", url, data, true, successHandler, errorHandler);
	}
}
//获取请求url地址的参数
common.GetParameters = function(){
	var url = location.search; //获取url中"?"符后的字串
	var theRequest = new Object();
	if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      strs = str.split("&");
      for(var i = 0; i < strs.length; i ++) {
         theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
      }
	}
	return theRequest;
}
//获得小数点后两位
common.parseFloat = function(num){
	common.parseFloat(num, 2);
}
//根据长度获得数字
common.parseFloat = function(num, length){
	var s = num + "";
	var str = s.substring(0,s.indexOf(".") + length);
	var count = parseFloat(str);
	return count;
}

common.substr = function(str, start, end) {
	var opStr = str;
	if (opStr != null) {
		if (opStr.length > end) {
			opStr = opStr.substring(start, end);
		} else {
			opStr = opStr.substring(start, str.length);
		}
		return opStr;
	} else {
		return "";
	}
}

common.GetType = function(obj) {
	if(obj != null){
		var type = typeof obj;
		return type;
	} else {
		return 'null';
	}
}
//获取浏览器版本方法
common.GetBrowserType = function() {
	var ret = {}; //用户返回的对象
	var Sys = {};
	var ua = navigator.userAgent.toLowerCase();
	var s;
	if(navigator.appVersion.match(/MSIE 6./i) == "6.") {
		ret.type = "IE";
		ret.version = 6;
		return ret;
	} else {
		(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
			(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
				(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
					(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
						(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
	}
	if (Sys.ie) {
		ret.type = "IE";
		ret.version = Sys.ie;
	} else if (Sys.firefox) {
		ret.type = "Firefox";
		ret.version = Sys.firefox;
	} else if (Sys.chrome) {
		ret.type = "Chrome";
		ret.version = Sys.chrome;
	} else if (Sys.opera) {
		ret.type = "Opera";
		ret.version = Sys.opera;
	} else if (Sys.safari) {
		ret.type = "Safari";
		ret.version = Sys.safari;
	}
	return ret;
}

//去空格方法
common.string.Trim = function(str){
    return str.replace(/(^\s*)|(\s*$)/g, "");
}
common.string.lTrim = function(str){
    return str.replace(/(^\s*)/g,"");
}
common.string.rTrim = function(str){
    return str.replace(/(\s*$)/g,"");
}
common.string.Contain = function(parentStr, childStr){
	var contain = false;
	if(parentStr.indexOf(childStr) > -1){
		contain = true;
	}
	return contain;
}

// 时间戳函数
var _st = window.setTimeout;
window.setTimeout = function(fRef, mDelay){
    if (typeof fRef == "function") {
        var argu = Array.prototype.slice.call(arguments,2);
        var f = (function(){fRef.apply(null,argu)});
        return _st(f,mDelay);
    }
    return _st(fRef, mDelay);
}